package com.kylin

import java.util.Properties

import com.kylin.ItemCF.{mysql_driver, mysql_pwd, mysql_user}
import org.apache.spark.sql.{SaveMode, SparkSession}

object Rarings2mysql {

  val mysql_user="root"
  val mysql_pwd ="root"
  val mysql_driver="com.mysql.jdbc.Driver"
  val mysql_url = "jdbc:mysql://115.29.140.3:3306/febs_food_itemcf?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"

  def main(args: Array[String]): Unit = {

    val connectionProperties = new Properties
    //connectionProperties.setProperty("dbtable", "data")
    connectionProperties.setProperty("user", mysql_user)
    connectionProperties.setProperty("password", mysql_pwd)
    connectionProperties.setProperty("driver", mysql_driver)
    connectionProperties.setProperty("truncate","true")

    val spark = SparkSession.builder.appName("ItemCF").master("local[*]").getOrCreate()
    val df =spark.read.format("csv").option("header","true").csv("/Users/kylin/Documents/workspace/FEBS-Vue-itemcf/engine/src/main/java/com/kylin/ratings.csv")

    df.printSchema()
    df.show(10)
    df.write.mode(SaveMode.Overwrite).jdbc(mysql_url,"ratings",connectionProperties)


  }

}
